/*
 * Copyright 2011 Christoph Ludwig (christoph[at]chludwig.de). All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.chludwig.ehumanities.provenance.jaxb;

import java.net.URL;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response.Status;
import javax.xml.XMLConstants;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import org.xml.sax.SAXException;

import de.chludwig.ehumanities.provenance.resources.ProvenanceRoot;

/**
 * 
 */
public class HPTSchemaFactory {

  public static Schema createWorkflowContainerSchema() {
    URL schemaURL = ProvenanceRoot.class.getClassLoader().getResource("schemas/workflowContainer.xsd");
    return createSchema(schemaURL);
  }

  /**
   * @param schemaURL
   * @return
   */
  public static Schema createSchema(URL schemaURL) {
    Schema schema;
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    try {
      schema = sf.newSchema(schemaURL);
    }
    catch (SAXException saxe) {
      throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
    return schema;
  }


}
